package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TbStationStatus;
import com.ruoyi.system.service.ITbStationStatusService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 测试站状态Controller
 * 
 * @author nonghg
 * @date 2022-01-09
 */
@Controller
@RequestMapping("/system/status")
public class TbStationStatusController extends BaseController
{
    private String prefix = "system/status";

    @Autowired
    private ITbStationStatusService tbStationStatusService;

    @RequiresPermissions("system:status:view")
    @GetMapping()
    public String status()
    {
        return prefix + "/status";
    }

    /**
     * 查询测试站状态列表
     */
    @RequiresPermissions("system:status:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbStationStatus tbStationStatus)
    {
        startPage();
        List<TbStationStatus> list = tbStationStatusService.selectTbStationStatusList(tbStationStatus);
        return getDataTable(list);
    }

    /**
     * 导出测试站状态列表
     */
    @RequiresPermissions("system:status:export")
    @Log(title = "测试站状态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbStationStatus tbStationStatus)
    {
        List<TbStationStatus> list = tbStationStatusService.selectTbStationStatusList(tbStationStatus);
        ExcelUtil<TbStationStatus> util = new ExcelUtil<TbStationStatus>(TbStationStatus.class);
        return util.exportExcel(list, "测试站状态数据");
    }

    /**
     * 新增测试站状态
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存测试站状态
     */
    @RequiresPermissions("system:status:add")
    @Log(title = "测试站状态", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbStationStatus tbStationStatus)
    {
        return toAjax(tbStationStatusService.insertTbStationStatus(tbStationStatus));
    }

    /**
     * 修改测试站状态
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TbStationStatus tbStationStatus = tbStationStatusService.selectTbStationStatusById(id);
        mmap.put("tbStationStatus", tbStationStatus);
        return prefix + "/edit";
    }

    /**
     * 修改保存测试站状态
     */
    @RequiresPermissions("system:status:edit")
    @Log(title = "测试站状态", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbStationStatus tbStationStatus)
    {
        tbStationStatus.setUpdateTime(DateUtils.getNowDate());
        return toAjax(tbStationStatusService.updateTbStationStatus(tbStationStatus));
    }

    /**
     * 删除测试站状态
     */
    @RequiresPermissions("system:status:remove")
    @Log(title = "测试站状态", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbStationStatusService.deleteTbStationStatusByIds(ids));
    }
}
